//
//  XMDiscoverController.m
//  XMWeibo
//
//  Created by chi on 14-8-20.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMDiscoverController.h"
#import "XMSearchBar.h"

//搜索栏距离宽度
#define kHSearchBarEdge (22.0)
#define kVSearchBarEdge (8.0)

@interface XMDiscoverController ()<UITextFieldDelegate>

@end

@implementation XMDiscoverController



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if (isIOS7) {
        self.tableView.contentInset = UIEdgeInsetsMake(-25.0, 0, 0, 0);
    }
    
    //创建搜索框
    XMSearchBar *searchBar = [[XMSearchBar alloc]init];

    //调整位置
    CGFloat barHeight = 44;

    CGFloat barWidth = self.view.bounds.size.width;
    
    CGRect tmp = CGRectMake(0.0, 0.0, self.view.bounds.size.width - 2 * kHSearchBarEdge, barHeight - kVSearchBarEdge * 2);
    
    searchBar.bounds = tmp;
    searchBar.center = CGPointMake(barWidth * 0.5, barHeight * 0.5);
    //设置代理
    searchBar.delegate = self;
    
    self.navigationItem.titleView = searchBar;
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(clickCancelButton)];
    
    // 添加组
    [self setupGroup1];
    [self setupGroup2];
    [self setupGroup3];
    
    
}



- (void)setupGroup1
{
    XMGroupInfo *group1 = [self addGroup];
    
    
    XMBaseSettingItem *hotStatus = [XMArrowSettingItem arrowCellItemWithTitle:@"热门微博" subTitle:@"笑话、娱乐都搬到这里啦" icon:@"hot_status" class:nil];
    
    XMBaseSettingItem *find_people = [XMArrowSettingItem arrowCellItemWithTitle:@"找人" subTitle:@"名人、有意思的人尽在这里" icon:@"find_people" class:nil];
    
    group1.cellItems = @[hotStatus, find_people];
    
}

- (void)setupGroup2
{
    XMGroupInfo *group2 = [self addGroup];
    
    
    XMBaseSettingItem *game_center = [XMArrowSettingItem arrowCellItemWithTitle:@"游戏中心" subTitle:nil icon:@"game_center" class:nil];
    
    XMBaseSettingItem *near = [XMArrowSettingItem arrowCellItemWithTitle:@"周边" subTitle:nil icon:@"near" class:nil];
    
     XMBaseSettingItem *app = [XMArrowSettingItem arrowCellItemWithTitle:@"应用" subTitle:nil icon:@"app" class:nil];
    
    group2.cellItems = @[game_center, near, app];
    
}

- (void)setupGroup3
{
    XMGroupInfo *group3 = [self addGroup];
    
    XMBaseSettingItem *video = [XMArrowSettingItem arrowCellItemWithTitle:@"视频" subTitle:nil icon:@"video" class:nil];
    
    
    XMBaseSettingItem *music = [XMArrowSettingItem arrowCellItemWithTitle:@"音乐" subTitle:nil icon:@"music" class:nil];
    
    XMBaseSettingItem *movie = [XMArrowSettingItem arrowCellItemWithTitle:@"电影" subTitle:nil icon:@"movie" class:nil];
    
    XMBaseSettingItem *cast = [XMArrowSettingItem arrowCellItemWithTitle:@"播客" subTitle:nil icon:@"cast" class:nil];
    XMBaseSettingItem *more = [XMArrowSettingItem arrowCellItemWithTitle:@"更多" subTitle:nil icon:@"more" class:nil];
    
    group3.cellItems = @[video, music, movie, cast, more];
    
}



- (void)clickCancelButton
{
    [self.navigationItem.titleView endEditing:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.navigationItem.titleView endEditing:YES];
    
    XMLog(@"按了搜索键 come here");
    
    return YES;
}

@end
